#### @martysama0134 save scripts ####
## Inside /etc/crontab paste: (for automatic backups every hour)
# 0	*	*	*	*	root	make -C /home/metin2/save/fs dump
## for automatic clean of backups older than 7 days every week:
# 0	0	*	*	1	root	make -C /home/metin2/save/fs wclean

DATE != date +%Y%m%d-%H%M%S

CURPATH != pwd
PATH = ../../
FOLD = files
PATH2 = $(PATH)$(FOLD)
OUTPATH = .

all:
	@echo "available all, dump, recovery and clean"

dump:
	@cd $(PATH) && ./clear.py
	@cd $(CURPATH) && cd $(PATH) && tar -czf serverfiles_$(DATE).tgz $(FOLD)
	@mv $(PATH)serverfiles_$(DATE).tgz $(OUTPATH)

recovery:
	@tar -xzf serverfiles.tgz -C $(PATH)

clean:
	@rm -f $(OUTPATH)/*.tgz

lclean:
	@cat /dev/null > $(MY_LOGF)

wclean:
	@echo "### clean week begin $(DATE)" >> $(MY_LOGF)
	@find $(OUTPATH) -name "*.tgz" -type f -mtime +7 -print -delete >> $(MY_LOGF)
	@echo "### clean week end $(DATE)" >> $(MY_LOGF)
